package util;

import collection.ATree;
import collection.ATreeNode;
import collection.BinTree;
import collection.IStack;
import collection.ListStack;

public class TreeUtil {
	
	private static <N extends ATreeNode<Integer>> int sumTreeNode(ATree<N,Integer> tree, N treeNode)
	{
		int sum = 0;
		if (tree.isInternal(treeNode))
		{
			for (N child : tree.getChildren(treeNode))
			{
				sum += sumTreeNode(tree, child);
			}
		}
		sum += treeNode.getElement();
		
		return sum;
	}
	
	public static <N extends ATreeNode<Integer>> int sumTree(ATree<N,Integer> tree)
	{
		return sumTreeNode(tree, tree.getRoot());
	}

}
